package com.kongmou.SpringBatch.controller;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class BatchController {

    @Resource
    private JobLauncher jobLauncher;

    @Resource
    private Job importJob;

    public JobParameters jobParameters;

    @RequestMapping("/read")
    public String imp(String fileName) throws Exception{

        String path = fileName+".csv";
       jobParameters = new JobParametersBuilder()
               .addString("input.file.name", path)
               .addLong("time", System.currentTimeMillis())
               .toJobParameters();
       jobLauncher.run(importJob, jobParameters);
       return "ok";
    }
}
